import { SkillCategoryModel } from '../../models/SkillCategory'

export default defineEventHandler(async (event) => {
  try {
    const body = await readBody(event)
    
    // 验证必填字段
    if (!body.name) {
      return {
        success: false,
        message: '分类名称不能为空',
        data: null
      }
    }
    
    const categoryId = await SkillCategoryModel.create({
      name: body.name,
      description: body.description || '',
      color: body.color || '#3b82f6',
      icon: body.icon || 'fa:code'
    })
    
    return {
      success: true,
      message: '创建技能分类成功',
      data: { id: categoryId }
    }
  } catch (error: any) {
    console.error('创建技能分类失败:', error)
    
    return {
      success: false,
      message: `创建技能分类失败: ${error.message}`,
      data: null
    }
  }
})